//
//  WYHttpServer+WYRegisterAndLogin.m
//  Tailor
//
//  Created by admin on 2018/2/3.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYHttpServer+WYRegisterAndLogin.h"

@implementation WYHttpServer (WYRegisterAndLogin)
+(void)masterLogin:(NSString *)username Withpassword:(NSString *)password SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{
    AFHTTPSessionManager *manager=[[WYHttpServer sharedInstance] requestManager];
    NSMutableDictionary *parm=[[WYHttpServer sharedInstance] requestParameters];
    [parm setValue:username forKey:@"telephone"];
    [parm setValue:password forKey:@"loginPassword"];
    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlLogin WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
        completion(success,response,errorMsg);
    }];
}

+(void)registeredNumber:(NSString *)username WithPassword:(NSString *)password WithCode:(NSString *)code SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{
    
    AFHTTPSessionManager *manager=[[WYHttpServer sharedInstance] requestManager];
    NSMutableDictionary *parm=[[WYHttpServer sharedInstance] requestParameters];
    [parm setValue:username forKey:@"telephone"];
    [parm setValue:password forKey:@"password"];
    [parm setValue:code forKey:@"code"];
    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlRegister WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
        completion(success,response,errorMsg);
    }];
    
    
    
}
+(void)editNumber:(NSString *)number Withpassword:(NSString *)password WithCode:(NSString *)code  WithHeadImg:(NSString *)headImg SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{
    AFHTTPSessionManager *manager=[[WYHttpServer sharedInstance] requestManager];
    NSMutableDictionary *parm=[[WYHttpServer sharedInstance] requestParameters];
    [parm setValue:number forKey:@"telephone"];
    [parm setValue:password forKey:@"password"];
    [parm setValue:code forKey:@"code"];
    [parm setValue:headImg forKey:@"headImg"];
    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlUpdatePassword WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
        completion(success,response,errorMsg);
    }];
}



+(void)editPassword:(NSString *)oldPwd WithNewpassword:(NSString *)password SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{

//    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlUpdatePassword WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
//        completion(success,response,errorMsg);
//    }];
    
}
+(void)upLoadImage:(NSString *)file WithImage:(UIImage *)image  SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{
//   NSData * iamgeData = UIImageJPEGRepresentation(image,0.5);
//    AFHTTPSessionManager *manager=[[WYHttpServer sharedInstance] requestManager];
//    manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"multipart/form-data"];
//    NSMutableDictionary *parm=[[WYHttpServer sharedInstance] requestParameters];
//    [parm setValue:file forKey:@"file"];
//
//    [manager POST:kUrlUpLoadImg parameters:parm constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
//        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//        // 设置时间格式
//        formatter.dateFormat = @"yyyyMMddHHmmss";
//        NSString *str = [formatter stringFromDate:[NSDate date]];
//        NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
//        [formData appendPartWithFileData :iamgeData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
//    } progress:^(NSProgress * _Nonnull uploadProgress) {
//
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:NULL];
//        //      NSDictionary *dic = [WYHttpServer responseConfiguration:responseObject];
//        if (![dic isKindOfClass:[NSDictionary class]]) {
//            HUDNormal(@"服务器闹点小情绪,努力安抚中,请稍候~");
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"hiddenLoading" object:nil];
//            return;
//        }
//        if ([dic[@"code"] integerValue]==0) {
//             completion(YES,dic,nil);
//
//        }else{
//            completion(NO,dic,dic[@"msg"]);
//        }
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
//    }];
    
    
//    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlUpLoadImg WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
//        completion(success,response,errorMsg);
//    }];
}
+(void)sendMessageWithTelephone:(NSString *)telephone SucessBlock:(void(^)(BOOL success,id response,NSString *errorMessage))completion
{
    AFHTTPSessionManager *manager=[[WYHttpServer sharedInstance] requestManager];
    NSMutableDictionary *parm=[[WYHttpServer sharedInstance] requestParameters];
    [parm setValue:telephone forKey:@"telephone"];
    [[WYHttpServer sharedInstance] postOperationWithManger:manager Url:kUrlSendMessage WithPara:parm Success:^(BOOL success, id response, NSString *errorMsg) {
        completion(success,response,errorMsg);
    }];
}
@end
